package com.zhang.apidriver.service.impl;

import com.zhang.apidriver.remote.ServiceDriverClient;
import com.zhang.apidriver.remote.ServiceMapClient;
import com.zhang.apidriver.service.PointService;
import com.zhang.internalcommon.dto.ApiDriverPointRequest;
import com.zhang.internalcommon.dto.Car;
import com.zhang.internalcommon.dto.PointRequest;
import com.zhang.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 类功能描述
 *
 * @author Kye
 * @date 2025-04-15
 */
@Service
public class PointServiceImpl implements PointService {
	@Autowired
	private ServiceDriverClient serviceDriverClient;
	@Autowired
	private ServiceMapClient serviceMapClient;

	@Override
	public ResponseResult upload(ApiDriverPointRequest apiDriverPointRequest) {
		// 	获取carId
		Long carId = apiDriverPointRequest.getCarId();

		// 	通过carId 获取tid、trid，调用service-driver-user接口
		ResponseResult<Car> carById = serviceDriverClient.getCarById(carId);
		Car car = carById.getData();
		String tid = car.getTid();
		String trid = car.getTrid();

		// 调用地图上传
		PointRequest pointRequest = new PointRequest();
		pointRequest.setTid(tid);
		pointRequest.setTrid(trid);
		pointRequest.setPoints(apiDriverPointRequest.getPoints());

		return serviceMapClient.upload(pointRequest);
	}
}
